package com.jy.rhin.application.document;

import com.jy.framework.base.entity.Result;
import com.jy.rhin.application.assembler.DocumentSubAndPubAssembler;
import com.jy.rhin.application.infra.NotificationApplicationService;
import lombok.extern.slf4j.Slf4j;
import org.oasis_open.docs.wsn.b_2.*;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

@Slf4j
@Service
public class DocumentSubAndPubService {

    @Resource
    NotificationApplicationService notificationApplicationService;

    public SubscribeResponse documentSubscribe(Subscribe message) {
        return DocumentSubAndPubAssembler.toSubscribeResponse(
                Result.success(notificationApplicationService.businessSubscribeTopic(DocumentSubAndPubAssembler.toDto(message))));
    }

    public UnsubscribeResponse documentUnSubscribe(Unsubscribe message) {
        return DocumentSubAndPubAssembler.toUnsubscribeResponse( Result.success(notificationApplicationService
                .cancelSubscribe(DocumentSubAndPubAssembler.toDto(message))));
    }

    public PauseSubscriptionResponse documentPauseSubscribe(PauseSubscription message) {
        return DocumentSubAndPubAssembler.toPauseSubscriptionResponse(Result.success(notificationApplicationService
                .pauseSubscribe(DocumentSubAndPubAssembler.toDto(message))));
    }

    public ResumeSubscriptionResponse documentResumeSubscribe(ResumeSubscription message) {
        return DocumentSubAndPubAssembler.toResumeSubscriptionResponse( Result.success(notificationApplicationService
                .resumeSubscribe(DocumentSubAndPubAssembler.toDto(message))));
    }

}
